package com.zhf.servlet.class1;

import com.zhf.entity.Class1;
import com.zhf.entity.Page;
import com.zhf.entity.Student;
import com.zhf.service.ClassService;
import com.zhf.service.impl.ClassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ClassQueryServlet", urlPatterns = "/classQueryAll")
public class ClassQueryServlet extends HttpServlet {
    ClassService classService = new ClassServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String currentPage = request.getParameter("currentPage");
        if (currentPage == null) {
            currentPage = "1";
        }
        Page<Class1> page = new Page<>();
        int current =Integer.parseInt(currentPage);
        page.setCurrentPage(current);
        page.setPageSize(5);
        List<Class1> class1List = classService.queryAllClass(page);
        request.setAttribute("class1List", class1List);
        request.setAttribute("page", page);
        request.getRequestDispatcher("Classindex.jsp").forward(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
